package com.byjh.api;


import com.byjh.app.domain.Document;
import com.byjh.app.domain.DocumentType;
import com.byjh.app.dto.DocumentSearchDto;
import com.byjh.app.service.IDocumentService;
import com.byjh.app.service.IDocumentTypeService;
import com.byjh.common.annotation.Anonymous;
import com.byjh.common.core.controller.BaseController;
import com.byjh.common.core.domain.R;
import com.byjh.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/api/document")
public class DocumentApi extends BaseController {


    @Resource
    private IDocumentService documentService;
    @Resource
    private IDocumentTypeService documentTypeService;


    @GetMapping("/typeList")
    @Anonymous
    public R<List<DocumentType>> typeList() {
        return R.ok(documentTypeService.selectDocumentTypeList(null));
    }

    @GetMapping("/documentList")
    @Anonymous
    public TableDataInfo documentList(DocumentSearchDto dto) {
        startPage();
        List<Document> list = documentService.selectDocumentList(new Document().setTypeId(dto.getTypeId()).setName(dto.getKeyword()).setFormat(dto.getFormat()));
        return getDataTable(list);
    }

}
